function [S_min,fval] = SqpOpt(r,T,T_range,lb,ub,S0,contype)
% SQP
if T_range
    fun = @(S)AvgGdop(T_range,S);
else
    fun = @(S)SingleGdop(T,S);
end
A = [];
b = [];
Aeq = [];
beq = [];
% options = optimoptions('fmincon','Display','iter','Algorithm','sqp','PlotFcn','optimplotfvalconstr');
options = optimset('Algorithm','sqp','PlotFcn',@optimplotfval);
nonlcon = @(S)mycon(T,S,contype,r);
[S_min,fval] = fmincon(fun,S0,A,b,Aeq,beq,lb,ub,nonlcon,options);
end
    
